package main

import (
	"encoding/json"
	"fmt"
)

type SendEmail interface {
	send()
}

type user struct {
	name  string
	email string
}

func (u *user) send() {
	fmt.Println(u.name + " email is " + u.email + "already send")
}

type admin struct {
	name  string
	email string
}

func (a *admin) send() {
	fmt.Println(a.name + " email is " + a.email + "already send")
}

type Stu struct {
	Name  string `json:"name"`
	Age   int
	HIgh  bool
	sex   string
	Class *Class `json:"class"`
}

type Class struct {
	Name  string
	Grade int
}

func main() {
	//实例化一个数据结构，用于生成json字符串
	stu := Stu{
		Name: "张三",
		Age:  18,
		HIgh: true,
		sex:  "男",
	}

	//指针变量
	cla := new(Class)
	cla.Name = "1班"
	cla.Grade = 3
	stu.Class = cla

	//Marshal失败时err!=nil
	jsonStu, err := json.Marshal(stu)
	if err != nil {
		fmt.Println("生成json字符串错误")
	}

	//jsonStu是[]byte类型，转化成string类型便于查看
	fmt.Println(string(jsonStu))
}

//func main() {

//var a interface{}
////a = "sss"
//if aType, ok := a.(string);ok{
//	fmt.Println(ok)
//	fmt.Println(aType)
//}else {
//	fmt.Println(ok)
//	fmt.Println(aType)
//
//}

//u := &user{
//	name:  "asong",
//	email: "你猜",
//}
//a := &admin{
//	name:  "asong1",
//	email: "就不告诉你",
//}
//Send(u)
//Send(a)
//}

func Send(s SendEmail) {
	s.send()
}
